package com.ruoyi.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.ChronicDisease;
import com.ruoyi.service.IChronicDiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * diseaseController
 * 
 * @author ruoyi
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/disease")
public class ChronicDiseaseController extends BaseController
{
    @Autowired
    private IChronicDiseaseService chronicDiseaseService;

    /**
     * 查询disease列表
     */
    @RequiresPermissions("disease:disease:list")
    @GetMapping("/list")
    public TableDataInfo list(ChronicDisease chronicDisease)
    {
        startPage();
        List<ChronicDisease> list = chronicDiseaseService.selectChronicDiseaseList(chronicDisease);
        return getDataTable(list);
    }

    /**
     * 导出disease列表
     */
    @RequiresPermissions("disease:disease:export")
    @Log(title = "disease", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChronicDisease chronicDisease)
    {
        List<ChronicDisease> list = chronicDiseaseService.selectChronicDiseaseList(chronicDisease);
        ExcelUtil<ChronicDisease> util = new ExcelUtil<ChronicDisease>(ChronicDisease.class);
        util.exportExcel(response, list, "disease数据");
    }

    /**
     * 获取disease详细信息
     */
    @RequiresPermissions("disease:disease:query")
    @GetMapping(value = "/{dCid}")
    public AjaxResult getInfo(@PathVariable("dCid") Long dCid)
    {
        return success(chronicDiseaseService.selectChronicDiseaseByDCid(dCid));
    }

    /**
     * 新增disease
     */
    @RequiresPermissions("disease:disease:add")
    @Log(title = "disease", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChronicDisease chronicDisease)
    {
        return toAjax(chronicDiseaseService.insertChronicDisease(chronicDisease));
    }

    /**
     * 修改disease
     */
    @RequiresPermissions("disease:disease:edit")
    @Log(title = "disease", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChronicDisease chronicDisease)
    {
        return toAjax(chronicDiseaseService.updateChronicDisease(chronicDisease));
    }

    /**
     * 删除disease
     */
    @RequiresPermissions("disease:disease:remove")
    @Log(title = "disease", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dCids}")
    public AjaxResult remove(@PathVariable Long[] dCids)
    {
        return toAjax(chronicDiseaseService.deleteChronicDiseaseByDCids(dCids));
    }
}
